﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using Microsoft.Practices.Unity;
using Microsoft.Practices.Unity.Configuration;
using Leo.BL;
using Leo.Entities;

namespace VeterinariaDrLeo.Controllers
{
    public class ServicioController : Controller
    {
        //
        // GET: /Servicio/
        [Dependency]
        public IServicioBL ServicioBl { get; set; }

        public ActionResult Index()
        {
            var ListarServ = ServicioBl.GetFromServicioByCriterio("");
            return View(ListarServ);
        }

        [HttpPost]
        public ActionResult Index(string criterio = "")
        {
            var ListarServ = ServicioBl.GetFromServicioByCriterio(criterio);
            return View(ListarServ);
        }

        public ActionResult Create()
        {
            var crearServ = ServicioBl.GetFromServicioByCriterio("");
            return View();
        }

        [HttpPost]
        public ActionResult Create(Servicio servicio)
        {
            try
            {
                ServicioBl.AddServicio(servicio);
                return RedirectToAction("index");
            }
            catch
            {
                return View();
            }

        }

        public ActionResult Edit(Int32 id)
        {
            var servicio = ServicioBl.GetFromServicioById(id);
            return View(servicio);
        }

        [HttpPost]
        public ActionResult Edit(int id, Servicio servicio)
        {
            try
            {
                ServicioBl.UpdateServicio(servicio);
                return RedirectToAction("index");
            }
            catch
            {
                return View();
            }
        }

        public ActionResult Delete(int id)
        {
            ServicioBl.RemoveServicio(id);
            return RedirectToAction("index");
        }

        [HttpPost]
        public ActionResult Delete(int id, FormCollection collection)
        {
            try
            {
                return RedirectToAction("index");
            }

            catch
            {
                return View();
            }

        }
    }
}
